package com.projetoptymo;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.TextView;
import android.widget.ToggleButton;



public class SettingsActivity extends Activity implements OnClickListener
{
	int busstop_count;
	TextView textbuscount;
	
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.settingslayout);
		
		
		Button btnMoins = (Button) findViewById(R.id.minusbtn);
		btnMoins.setOnClickListener(this);
		
		Button btnPlus = (Button) findViewById(R.id.plusbtn);
		btnPlus.setOnClickListener(this);
		
		Button btnSave = (Button) findViewById(R.id.savebtn);
		btnSave.setOnClickListener(this);
		
		// on met les valeurs.
		SharedPreferences pref = getSharedPreferences("settings", MODE_PRIVATE);
		
		boolean satellite_mode = pref.getBoolean("satellite_mode", true);
		busstop_count = pref.getInt("busstop_count", 5);
		
		ToggleButton satmode = (ToggleButton) findViewById(R.id.ToggleButtonSatMode);
		satmode.setChecked(satellite_mode);
		
		textbuscount = (TextView) findViewById(R.id.TextViewBusStopCount);
		textbuscount.setText(String.valueOf(busstop_count));
		
		
	}
	
	@Override
	public void onClick(View v)
	{
		switch(v.getId())
		{
		case R.id.minusbtn:
			if(busstop_count>1)
				busstop_count--;
			textbuscount.setText(String.valueOf(busstop_count));
			break;
			
		case R.id.plusbtn:
			if(busstop_count<10)
				busstop_count++;
			textbuscount.setText(String.valueOf(busstop_count));
			break;
		
		case R.id.savebtn:
			SharedPreferences pref = getSharedPreferences("settings", MODE_PRIVATE);
			SharedPreferences.Editor editor = pref.edit();
			
			editor.putInt("busstop_count", busstop_count);
			
			ToggleButton satmode = (ToggleButton) findViewById(R.id.ToggleButtonSatMode);
			editor.putBoolean("satellite_mode", satmode.isChecked());
			
			editor.commit();
			
			finish();
			break;
		}
	}
	
}
